#ifndef __TCP_CONNECTION__
#define __TCP_CONNECTION__
#include"SocketIO.h"
#include"Socket.h"
#include<string>
#include<functional>
using std::function;
using std::string;
#include<memory>
#include<iostream>
using std::shared_ptr;
using std::endl;
using std::cout;


class Tcpconnection;
using TcpConnectionPtr = shared_ptr<Tcpconnection>;
using TcpConnectionCallback = function<void(const TcpConnectionPtr &)>;
class Tcpconnection
:public std::enable_shared_from_this<Tcpconnection>
{
public: 
    Tcpconnection(int fd);
    ~Tcpconnection();
    void send(const string &msg);
    string recv();
    void setNewConneciton(TcpConnectionCallback _cb);
    void setNewMessage(TcpConnectionCallback _cb);
    void setNewClose(TcpConnectionCallback _cb);
    void handlNewConnection();
    void handlNewMessage();
    void handlNeclose();
private:
    TcpConnectionCallback _onNewConnection;
    TcpConnectionCallback _onNewMessage;
    TcpConnectionCallback _onNewClose;
    Socket _socket;
    SocketIO _soIO;
};
#endif
